package com.smartens.boit.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.smartens.boit.R;
import com.smartens.boit.base.BaseActivity;

/**
 * @Description 设备使能多选
 * @Author songtt
 * @Date 2021/3/4
 */

public class MultipleActivity extends BaseActivity {
    private TextView cancel;
    private TextView save;
    private CheckBox checkBox1;
    private CheckBox checkBox2;
    private CheckBox checkBox3;
    private String typeText;
    private LinearLayout lin01;
    private LinearLayout lin02;
    private LinearLayout lin03;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multiple);
        cancel = findViewById(R.id.cancel);
        save = findViewById(R.id.save);
        checkBox1 = findViewById(R.id.rb_01);
        checkBox2 = findViewById(R.id.rb_02);
        checkBox3 = findViewById(R.id.rb_03);
        lin01 = findViewById(R.id.lin_01);
        lin02 = findViewById(R.id.lin_02);
        lin03 = findViewById(R.id.lin_03);
        Intent intent =getIntent();
        Bundle bundle= intent.getExtras();
        String type = bundle.getString("type");
        String enabling = bundle.getString("enabling");
        typeText = enabling;
        if(type != null){
            if("单相单控".equals(type)){
                checkBox1.setChecked(true);
                checkBox1.setEnabled(false);
                checkBox2.setChecked(false);
                checkBox2.setEnabled(false);
                checkBox3.setChecked(false);
                checkBox3.setEnabled(false);
                lin02.setBackgroundColor(getResources().getColor(R.color.gray));
                lin03.setBackgroundColor(getResources().getColor(R.color.gray));
                typeText = "A相";
            }else if("单相三控".equals(type)){
                checkBox1.setChecked(true);
                checkBox1.setEnabled(false);
                checkBox2.setChecked(false);
                checkBox2.setEnabled(false);
                checkBox3.setChecked(false);
                checkBox3.setEnabled(false);
                lin02.setBackgroundColor(getResources().getColor(R.color.gray));
                lin03.setBackgroundColor(getResources().getColor(R.color.gray));
                typeText = "A相";
            }else if("三相单控".equals(type)){
                setClick(enabling);

            }else if("三相三控".equals(type)){
                setClick(enabling);
            }
        }


        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MultipleActivity.this.finish();
            }
        });
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setClickText();
                Intent intent = new Intent(MultipleActivity.this,EquipmentInfoActivity.class);
                intent.putExtra("backType",typeText);
                setResult(1002, intent);
                //    结束当前这个Activity对象的生命
                finish();
            }
        });

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    public void setClick(String enabling){
        if("A相".equals(enabling)){
            checkBox1.setChecked(true);
            checkBox3.setChecked(false);
            checkBox2.setChecked(false);
        }else if("B相".equals(enabling)){
            checkBox1.setChecked(false);
            checkBox3.setChecked(true);
            checkBox2.setChecked(false);
        }else if("C相".equals(enabling)){
            checkBox1.setChecked(false);
            checkBox3.setChecked(false);
            checkBox2.setChecked(true);
        }else if("A相 B相".equals(enabling)){
            checkBox1.setChecked(true);
            checkBox2.setChecked(true);
            checkBox3.setChecked(false);
        }else if("A相 C相".equals(enabling)){
            checkBox1.setChecked(true);
            checkBox2.setChecked(false);
            checkBox3.setChecked(true);
        }else if("B相 C相".equals(enabling)){
            checkBox1.setChecked(false);
            checkBox3.setChecked(true);
            checkBox2.setChecked(true);
        }
        lin02.setBackgroundColor(Color.WHITE);
        lin03.setBackgroundColor(Color.WHITE);
        checkBox1.setEnabled(true);
        checkBox2.setEnabled(true);
        checkBox3.setEnabled(true);
    }

    public void setClickText(){
        if(checkBox1.isChecked() && !checkBox2.isChecked() && !checkBox3.isChecked()){
            typeText = "A相";
        }else if(!checkBox1.isChecked() && checkBox2.isChecked() && !checkBox3.isChecked()){
            typeText = "B相";
        }else if(!checkBox1.isChecked() && !checkBox2.isChecked() && checkBox3.isChecked()){
            typeText = "C相";
        }else if(checkBox1.isChecked() && checkBox2.isChecked() && !checkBox3.isChecked()){
            typeText = "A相 B相";
        }else if(checkBox1.isChecked() && !checkBox2.isChecked() && checkBox3.isChecked()){
            typeText = "A相 C相";
        }else if(!checkBox1.isChecked() && checkBox2.isChecked() && checkBox3.isChecked()){
            typeText = "B相 C相";
        }
    }


}